<?php
/**
 * Created by PhpStorm.
 * User: shuai
 * Date: 2016/7/27
 * Time: 20:59
 * 首页配置
 */
defined('IN_PHPCMS') or exit('No permission resources.');
pc_base::load_app_class('admin', 'admin', 0);
pc_base::load_app_class('foreground');
pc_base::load_sys_class('format', '', 0);
pc_base::load_sys_class('form', '', 0);
class index extends admin {

    public function __construct() {
        $this->shuafen_tips = pc_base::load_model('shuafen_tips_model');
        $this->member = pc_base::load_model('member_model');
        $this->shuafen_carousel = pc_base::load_model('shuafen_carousel_model');
        $this->shuafen_download_times = pc_base::load_model('shuafen_download_times_model');
        $this->shuafen_count_data = pc_base::load_model('shuafen_count_data_model');
        $this->thumb_info = array('module'=>'self_drive','upload_allowext'=>'jpg|jpeg|gif|png|bmp','isselectimage'=>1,'images_width'=>'','images_height'=>'','watermark'=>0,'show_type'=>1);
        parent::__construct();
    }

    public function trips(){
        $page = max(intval($_GET['page']), 1);
        $infos = $this->shuafen_tips->listinfo(array('is_show'=>'Y'), '', $page);
        $pages = $this->shuafen_tips->pages;
        include $this->admin_tpl('trips/trips_list');
    }

    public function add_trips(){
        if (isset($_POST['dosubmit'])) {
            $info = $_POST['info'];
            if($_POST['id']){
                $info['update_time'] = SYS_TIME;
                $id = $this->shuafen_tips->update($info, array('id'=>$_POST['id']));
                showmessage(L('修改成功'), 'index.php?m=shuafen&c=index&a=trips');
            }else{
                $info['create_time'] = SYS_TIME;
                $id = $this->shuafen_tips->insert($info, true);
                if ($id) {
                    showmessage(L('添加成功'), 'index.php?m=shuafen&c=index&a=trips');
                }else {
                    showmessage(L('operation_failure'), 'index.php?m=shuafen&c=index&a=trips');
                }
            }
        }else{
            $action = $_GET['action'];
            if($action){
                $id = $_GET['id'];
                $tips = $this->shuafen_tips->get_one(array('id'=>$id));
            }
        }
        include $this->admin_tpl('trips/add_trips');
    }

    public function delete_trips(){
        $id = $_GET['id'];
        if($id){
            $this->shuafen_tips->update(array('is_show'=>'N'),array('id'=>$id));
            showmessage(L('删除成功'), 'index.php?m=shuafen&c=index&a=trips');
        }
    }

    public function carousel(){
        $page = max(intval($_GET['page']), 1);
        $infos = $this->shuafen_carousel->listinfo(array('is_show'=>'Y'), '', $page);
        $pages = $this->shuafen_carousel->pages;
        include $this->admin_tpl('carousel/carousel_list');
    }

    public function add_carousel(){
        if (isset($_POST['dosubmit'])) {
            $info = $_POST['info'];
            if($_POST['id']){
                $info['update_time'] = SYS_TIME;
                $id = $this->shuafen_carousel->update($info, array('id'=>$_POST['id']));
                showmessage(L('修改成功'), 'index.php?m=shuafen&c=index&a=carousel');
            }else{
                $info['create_time'] = SYS_TIME;
                $id = $this->shuafen_carousel->insert($info, true);
                if ($id) {
                    showmessage(L('添加成功'), 'index.php?m=shuafen&c=index&a=carousel');
                }else {
                    showmessage(L('operation_failure'), 'index.php?m=shuafen&c=index&a=carousel');
                }
            }
        }else{
            $action = $_GET['action'];
            if($action){
                $id = $_GET['id'];
                $carousel = $this->shuafen_carousel->get_one(array('id'=>$id));
            }
        }
        include $this->admin_tpl('carousel/add_carousel');
    }

    public function delete_carousel(){
        $id = $_GET['id'];
        if($id){
            $this->shuafen_carousel->update(array('is_show'=>'N'),array('id'=>$id));
            showmessage(L('删除成功'), 'index.php?m=shuafen&c=index&a=carousel');
        }
    }

    public function free_down_num(){
        if (isset($_POST['dosubmit'])) {
            $data['free_add_down_times'] = $_POST['free_add_down_times'];
            $this->shuafen_download_times->update($data, array('id'=>$_POST['id']));
            showmessage(L('修改成功'), 'index.php?m=shuafen&c=index&a=free_down_num');
        }else{
            $num = $this->shuafen_download_times->get_one(array('id'=>1));
        }
        include $this->admin_tpl('download/free_down_num');
    }

    public function free_member(){
        $page = max(intval($_GET['page']), 1);
        $where = 'trash = 0 and add_times>0';
        if(isset($_GET['username']) && trim($_GET['username'])){
            $tel=$_GET['username'];
            $where .= " AND username = ".trim($_GET['username']);
        }
        $infos = $this->member->listinfo($where,'top desc , start_time desc , userid desc', $page);
        $pages = $this->member->pages;
        $top = array('0'=>'否','1'=>'是');
        $sex = array('0'=>'男','1'=>'女');
        include $this->admin_tpl('member/free_member');
    }

    public function top_free_member(){
        $userid = $_GET['userid'];
        if($userid){
            $action = $_GET['action'];
            if($action){
                $data['top'] = 0;
            }else{
                $data['top'] = 1;
                $data['start_time'] = SYS_TIME;
            }
            $this->member->update($data,array('userid'=>$userid));
            showmessage(L('操作成功'), 'index.php?m=shuafen&c=index&a=free_member');
        }
    }

    public function free_click(){
        $num = $this->shuafen_count_data->get_one(array('id'=>1));
        include $this->admin_tpl('free_click/free_click');
    }

    public function index_data_conf(){
        if (isset($_POST['dosubmit'])) {
            $data['index_data_conf'] = $_POST['index_data_conf'];
            $this->shuafen_download_times->update($data, array('id'=>$_POST['id']));
            showmessage(L('修改成功'), 'index.php?m=shuafen&c=index&a=index_data_conf');
        }else{
            $num = $this->shuafen_download_times->get_one(array('id'=>1));
        }
        include $this->admin_tpl('download/index_data_conf');
    }
}
